package com.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RibbitMQConfig {

    public static final String MIAOSHA_EXCHANGE = "MIAOSHA_EXCHANGE";
    public static final String MIAOSHA_QUEUE = "MIAOSHA_QUEUE";
    public static final String KEY_MIAOSHA = "KEY_MIAOSHA";

    /**
     * 创建直连类型交换机
     * 只能发送指定队列
     * @return
     */
    @Bean("MIAOSHA_EXCHANGE")
    public DirectExchange createDirectExchange()
    {
        return new DirectExchange(MIAOSHA_EXCHANGE);
    }

    /**
     * 创建直连类型交换机
     * 只能发送指定队列
     * @return
     */
    @Bean("TOPIC_EXCHANGE")
    public TopicExchange createTOPIC_Exchange()
    {
        return new TopicExchange("TOPIC_EXCHANGE");
    }



    @Bean("MIAOSHA_QUEUE")
    public Queue  createQueueMiaosha()
    {
        return new Queue(MIAOSHA_QUEUE);
    }

    @Bean("备胎队列")
    public Queue  createQueueBeitai()
    {
        return new Queue("备胎队列");
    }


    @Bean("binding_MiaoSha")
    public Binding binding_MiaoSha()
    {
         return BindingBuilder.bind(createQueueMiaosha()).to(createDirectExchange()).with(KEY_MIAOSHA);
    }

    @Bean("binding_Beitai")
    public Binding binding_Beitai()
    {
        return BindingBuilder.bind(createQueueBeitai()).to(createDirectExchange()).with("com.*");
    }


}
